package psbreeze.android.cocos2d.test;

import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.opengl.CCGLSurfaceView;

import psbreeze.android.cocos2d.test.scene.MainLayer;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity {
	private CCGLSurfaceView _glSurfaceView;
	
	// http://dan.clarke.name/2011/04/how-to-make-a-simple-android-game-with-cocos2d/
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        
        _glSurfaceView = new CCGLSurfaceView(this);
        
        setContentView(_glSurfaceView);
    }

	@Override
	protected void onStart() {
		super.onStart();
		
		CCDirector sharedDirector = CCDirector.sharedDirector();
		sharedDirector.attachInView(_glSurfaceView);
		sharedDirector.setDisplayFPS(true);
		sharedDirector.setAnimationInterval(1 / 60f);
		
		CCScene scene = CCScene.node();
		scene.addChild(new MainLayer(), 0);
		
		sharedDirector.runWithScene(scene);
	}

	@Override
	protected void onResume() {
		super.onResume();
		
		CCDirector.sharedDirector().resume();
	}

	@Override
	protected void onPause() {
		super.onPause();
		
		CCDirector.sharedDirector().pause();
	}

	@Override
	protected void onStop() {
		super.onStop();
		
		CCDirector.sharedDirector().end();
	}
}